﻿package net.wangit.framework.interceptor;

import net.wangit.Invocation;
import net.wangit.context.ActionContext;
import net.wangit.context.ActionContextImpl;
import net.wangit.framework.action.ActionMapping;
import net.wangit.framework.dispatcher.DefaultInvocation;
import net.wangit.framework.util.ActionCommandUtil;
import net.wangit.jdbc.Table;
import net.wangit.support.ActionInterceptor;
import net.wangit.util.Checker;

/**
 * 依据Action命令行，将表单数据转换为Table对象集合
 * 
 * @author watson
 * 
 */
public class LoadTablesAI implements ActionInterceptor {

	public LoadTablesAI() {
	}

	public void intercept(ActionContext ac, Invocation invocation)
			throws Exception {
		ActionMapping mapping = ((DefaultInvocation) invocation)
				.getActionMapping();
		String command = mapping.getCommand();
		if (!Checker.isEmpty(command)) {
			java.util.List<Table> tables = ActionCommandUtil.load(ac, mapping
					.getDomain(), command);
			((ActionContextImpl) ac).setTables(tables);
		}
		invocation.invoke();
	}
}
